package com.isesol.ime.validator.subscription;

import com.isesol.arch.fluentvalidator.*;
import com.isesol.ime.dal.mapper.*;
import com.isesol.ime.dal.model.*;
import com.isesol.ime.dal.model.dto.*;
import com.isesol.ime.enums.*;
import org.springframework.stereotype.*;

import javax.annotation.*;

@Component
public class SubscriptioStartUsingValidator extends ValidatorHandler<SubscriptionDTO> implements Validator<SubscriptionDTO> {

	@Resource
	SubscriptionMapper subscriptionMapper;

	@Override
	public boolean validate(ValidatorContext context, SubscriptionDTO subscriptionDTO) {

		boolean result = true;

		SubscriptionDO subscriptionDO = subscriptionMapper.getById(subscriptionDTO.getId());

		if (null == subscriptionDO) {

			context.addErrorMsg(ErrorCode.SUBSCR_NOT_EXIST.getMessage()+" ,SubId = " +subscriptionDTO.getId());
			result = false;

		}
		return  result;
	}
}